﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects;

namespace EasyBuildingCMS.BLL.CoreEngine
{

    public class BuildingBlockZoneRepository : CoreEngineBaseRepository
    {
        public BuildingBlockZoneRepository()
        {
            CacheKey += "_BuildingBlockZone";
        }

        public List<BuildingBlockZone> GetBuildingBlockZoneByMasterPageID(int masterPageID)
        {
            string key = CacheKey + "_masterpage_"+masterPageID;

            if (EnableCaching && Cache[key] != null)
            {
                return (List<BuildingBlockZone>)Cache[key];
            }

            this.CoreEngineContext.MasterPage.MergeOption = MergeOption.NoTracking;

            List<BuildingBlockZone> buildingBlockZones = (from zone in CoreEngineContext.BuildingBlockZones
                                      where zone.Active && zone.MasterPageID ==masterPageID
                                                          select zone).ToList();

            if (EnableCaching)
            {
                CacheData(key, buildingBlockZones, CacheDuration);
            }

            return buildingBlockZones;
        }

    }
}
